package com.dogkr.server.entity;

import java.util.Date;

public class UserMessage {
	private Long id;

	private Long userId;

	private Long msgFromId;

	private String msgFromName;

	private Short msgType;

	private String msgTitle;

	private Short isRead;

	private Short isAnswer;

	private Date lastModifydate;

	private Long msgAnswerId;

	private Date msgAnswerDate;

	private Long orderId;

	private Date createDate;
	
	private Date startDate;
	
	private Date endDate;

	private Short status;

	private String msgContent;

	private String remark;
	
	public enum Answer {
		ANSWER((short) 1), UNANSWERED((short) 0);

		short val;

		Answer(short val) {
			this.val = val;
		}

		public short getVal() {
			return val;
		}
	}
	
	public enum Read {
		READ((short) 1), UNREAD((short) 0);

		short val;

		Read(short val) {
			this.val = val;
		}

		public short getVal() {
			return val;
		}
	}

	public enum MsgType {
		MSG((short) 0), ORDER((short) 1), SYSTEM((short) 2);

		short val;

		MsgType(short val) {
			this.val = val;
		}

		public short getVal() {
			return val;
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Long getMsgFromId() {
		return msgFromId;
	}

	public void setMsgFromId(Long msgFromId) {
		this.msgFromId = msgFromId;
	}

	public String getMsgFromName() {
		return msgFromName;
	}

	public void setMsgFromName(String msgFromName) {
		this.msgFromName = msgFromName;
	}

	public Short getMsgType() {
		return msgType;
	}

	public void setMsgType(MsgType order) {
		this.msgType = order.getVal();
	}

	public void setMsgType(Short msgType) {
		this.msgType = msgType;
	}

	public String getMsgTitle() {
		return msgTitle;
	}

	public void setMsgTitle(String msgTitle) {
		this.msgTitle = msgTitle;
	}

	public Short getIsRead() {
		return isRead;
	}

	public void setIsRead(Read read) {
		this.isRead = read.getVal();
	}

	public void setIsRead(Short isRead) {
		this.isRead = isRead;
	}

	public Short getIsAnswer() {
		return isAnswer;
	}

	public void setIsAnswer(Short isAnswer) {
		this.isAnswer = isAnswer;
	}

	public void setIsAnswer(Answer answer) {
		this.isAnswer = answer.getVal();
	}

	public Date getLastModifydate() {
		return lastModifydate;
	}

	public void setLastModifydate(Date lastModifydate) {
		this.lastModifydate = lastModifydate;
	}

	public Long getMsgAnswerId() {
		return msgAnswerId;
	}

	public void setMsgAnswerId(Long msgAnswerId) {
		this.msgAnswerId = msgAnswerId;
	}

	public Date getMsgAnswerDate() {
		return msgAnswerDate;
	}

	public void setMsgAnswerDate(Date msgAnswerDate) {
		this.msgAnswerDate = msgAnswerDate;
	}

	public Long getOrderId() {
		return orderId;
	}

	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Short getStatus() {
		return status;
	}

	public void setStatus(Short status) {
		this.status = status;
	}

	public String getMsgContent() {
		return msgContent;
	}

	public void setMsgContent(String msgContent) {
		this.msgContent = msgContent;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * 创建订单预约通知.
	 * 
	 * @param orderId
	 * @param userId
	 * @return
	 */
	public static UserMessage createOrderMsg(Order order, Long userId) {
		UserMessage msg = new UserMessage();
		msg.setMsgType(UserMessage.MsgType.ORDER);
		msg.setMsgContent(order.getUserRemark());
		msg.setMsgTitle("您有新的预约");
		msg.setMsgFromId(order.getUserId());
		msg.setMsgFromName(order.getUserName());
		msg.setUserId(userId);
		msg.setOrderId(order.getId());
		msg.setCreateDate(new Date());
		msg.setIsRead(UserMessage.Read.UNREAD);
		msg.setIsAnswer(UserMessage.Answer.UNANSWERED);
		return msg;
	}

	/**
	 * 设置为已读
	 */
	public void setRead() {
		this.isRead = Read.READ.getVal();
	}

	public void setInsert(User user) {
		this.msgFromId = user.getId();
		this.msgFromName = user.getUserNickName();
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
}